# 普通方式实现员工增删改查
import requests

from common.get_token import grt_login_token


class IhrmRmpApi:
    @classmethod
    def add_emp(cls, token, req_data):
        # 添加员工
        resp = requests.post('http://ihrm-test.itheima.net/api/sys/user', headers={"Authorization": token},
                             json=req_data)
        return resp

    @classmethod
    def modify_emp(cls, epm_id, token, req_data):
        # 修改员工
        resp = requests.put('http://ihrm-test.itheima.net/api/sys/user/' + epm_id, headers={"Authorization": token},
                            json=req_data)
        return resp

    @classmethod
    def query_emp(cls, epm_id, token):
        # 查询员工
        resp = requests.get('http://ihrm-test.itheima.net/api/sys/user/' + epm_id, headers={"Authorization": token})
        return resp

    @classmethod
    def delete_emp(cls, epm_id, token):
        # 删除员工
        resp = requests.delete('http://ihrm-test.itheima.net/api/sys/user/' + epm_id, headers={"Authorization": token})
        return resp


if __name__ == '__main__':
    id = '1524644536645648384'
    token = grt_login_token()

    resp = IhrmRmpApi.add_emp(token, {"username": "二哈", "mobile": "17622244466",
                                      "workNumber": "76478126312"})
    print('添加员工', resp.json())

    resp = IhrmRmpApi.modify_emp(id, token, {"username": "俏丽哇"})
    print('修改员工', resp.json())

    resp = IhrmRmpApi.query_emp(id, token)
    print('查询员工', resp.json())

    resp = IhrmRmpApi.delete_emp(id, token)
    print('删除员工', resp.json())
